<html>
<head><meta charset="utf-8"><title>Promoting consts with `if` · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html">Promoting consts with `if`</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="176501820"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176501820" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176501820">(Sep 24 2019 at 20:19)</a>:</h4>
<p>Even when const <code>if</code> is implemented, we don't want to promote code like <code>&amp;(if true { 5 } else { 6 })</code>. However, we may want to do promotion when that <code>if</code> statement appears in the definition of a <code>const</code>.</p>
<div class="codehilite"><pre><span></span><span class="k">const</span><span class="w"> </span><span class="n">BRANCHY</span>: <span class="kt">i32</span> <span class="o">=</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="kc">true</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">5</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">6</span><span class="w"> </span><span class="p">};</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">x</span>: <span class="kp">&amp;</span><span class="nb">&#39;static</span><span class="w"> </span><span class="kt">i32</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="n">BRANCHY</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="176501999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176501999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176501999">(Sep 24 2019 at 20:21)</a>:</h4>
<p>If we do not want to promote <code>BRANCHY</code> in the previous code, we have a bit of a problem with backwards compatibility because of the way we lower <code>&amp;&amp;</code> and <code>||</code> to allow them in <code>const</code>s.</p>



<a name="176502160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176502160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176502160">(Sep 24 2019 at 20:22)</a>:</h4>
<p>Namely, <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=ece0858d50bc2fc32d534b2eaec53634" target="_blank" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=ece0858d50bc2fc32d534b2eaec53634">this code</a> compiles on stable but would stop compiling if we removed the destroy control flow hack that allows short circuiting logic in consts.</p>



<a name="176502161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176502161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176502161">(Sep 24 2019 at 20:22)</a>:</h4>
<p>I think that we're happy to promote such <code>const</code>s. We don't promote most <code>const fn</code>, but do promote <code>const</code>s that use them.</p>



<a name="176502259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176502259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176502259">(Sep 24 2019 at 20:23)</a>:</h4>
<p>You've not linked to you're actual example there.</p>



<a name="176502342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176502342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176502342">(Sep 24 2019 at 20:24)</a>:</h4>
<p>Does "this code" not have a hyperlink?</p>



<a name="176502361"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176502361" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176502361">(Sep 24 2019 at 20:24)</a>:</h4>
<p>It's linking to <code>https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018</code></p>



<a name="176502382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176502382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176502382">(Sep 24 2019 at 20:25)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="k">const</span><span class="w"> </span><span class="n">BOO</span>: <span class="kt">bool</span> <span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="kc">true</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="kc">false</span><span class="p">);</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">x</span>: <span class="kp">&amp;</span><span class="nb">&#39;static</span><span class="w"> </span><span class="kt">bool</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="n">BOO</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="176502405"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176502405" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176502405">(Sep 24 2019 at 20:25)</a>:</h4>
<p>oh duh sorry</p>



<a name="176502460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176502460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176502460">(Sep 24 2019 at 20:26)</a>:</h4>
<p>yea, we promote constants by looking at their type, nothing else</p>



<a name="176502510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176502510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176502510">(Sep 24 2019 at 20:26)</a>:</h4>
<p>(I think?)</p>



<a name="176502523"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176502523" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176502523">(Sep 24 2019 at 20:26)</a>:</h4>
<p>I guess the question is: is there any time where we don't want to promote <code>&amp;CONST</code>?</p>



<a name="176502565"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176502565" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176502565">(Sep 24 2019 at 20:26)</a>:</h4>
<p>So part of the result of the <code>mir_const_qualif</code> query is the qualifications of the return place of that <code>const</code></p>



<a name="176502570"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176502570" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176502570">(Sep 24 2019 at 20:26)</a>:</h4>
<p>so even <code>const FOO: Option&lt;Cell&lt;u32&gt;&gt; = None;</code> should not get promoted</p>



<a name="176502630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176502630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176502630">(Sep 24 2019 at 20:27)</a>:</h4>
<p>I'm wrong</p>



<a name="176502654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176502654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176502654">(Sep 24 2019 at 20:27)</a>:</h4>
<p>obviously</p>



<a name="176502658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176502658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176502658">(Sep 24 2019 at 20:27)</a>:</h4>
<p>uh</p>



<a name="176502720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176502720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176502720">(Sep 24 2019 at 20:28)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/blob/6ef275e6c3cb1384ec78128eceeb4963ff788dca/src/librustc_mir/transform/qualify_consts.rs#L1012" target="_blank" title="https://github.com/rust-lang/rust/blob/6ef275e6c3cb1384ec78128eceeb4963ff788dca/src/librustc_mir/transform/qualify_consts.rs#L1012">https://github.com/rust-lang/rust/blob/6ef275e6c3cb1384ec78128eceeb4963ff788dca/src/librustc_mir/transform/qualify_consts.rs#L1012</a></p>



<a name="176502739"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176502739" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176502739">(Sep 24 2019 at 20:28)</a>:</h4>
<p>yea</p>



<a name="176502754"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176502754" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176502754">(Sep 24 2019 at 20:28)</a>:</h4>
<p>but that should still work out correctly in your scheme, right?</p>



<a name="176502778"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176502778" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176502778">(Sep 24 2019 at 20:28)</a>:</h4>
<p>we'd get the worst qualifs of both arms</p>



<a name="176502859"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176502859" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176502859">(Sep 24 2019 at 20:29)</a>:</h4>
<p><code>const FOO: Option&lt;Cell&lt;u32&gt;&gt; = if false { Some(Cell::new(42)) } else {None};</code> will prevent <code>FOO</code> from getting promoted</p>



<a name="176502956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176502956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176502956">(Sep 24 2019 at 20:30)</a>:</h4>
<p>Yes, this is only tangentially related to dataflow-based qualification</p>



<a name="176503028"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176503028" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176503028">(Sep 24 2019 at 20:31)</a>:</h4>
<p>At the moment, <code>const BRANCHY: i32 = if true { 5 } else { 6 };</code> will also (I believe) be marked as unpromotable, because the return place is assigned to more than once.</p>



<a name="176503275"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176503275" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176503275">(Sep 24 2019 at 20:33)</a>:</h4>
<p>The question is whether we want that behavior or if we want to mark <code>BRANCHY</code> as promotable</p>



<a name="176503476"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176503476" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176503476">(Sep 24 2019 at 20:35)</a>:</h4>
<p>so this is a fun topic, because I've repeatedly tried to make the promotability depend on the <em>value</em> of the constant, so we could just eval it instead of looking at it</p>



<a name="176503540"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176503540" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176503540">(Sep 24 2019 at 20:36)</a>:</h4>
<p>then we'd only have to keep looking at associated constants</p>



<a name="176503575"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176503575" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176503575">(Sep 24 2019 at 20:36)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> hates me a bit more every time I bring it up, so obviously I'm gonna ping them</p>



<a name="176503577"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176503577" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176503577">(Sep 24 2019 at 20:36)</a>:</h4>
<p>anyway</p>



<a name="176503595"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176503595" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176503595">(Sep 24 2019 at 20:37)</a>:</h4>
<p>Doesn't <code>qualifs = self.qualifs_in_any_value_of_ty(body.return_ty());</code> ensure that integer constants are always promotable.</p>



<a name="176503754"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176503754" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176503754">(Sep 24 2019 at 20:38)</a>:</h4>
<p>Do you know if there's anything that could someday appear in a <code>const</code> body that would make us not want to promote <code>&amp;CONST</code> (stuff that's not covered by <code>HasMutInterior</code> and <code>NeedsDrop</code>? Maybe <code>!Sync</code> stuff?</p>



<a name="176503767"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176503767" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176503767">(Sep 24 2019 at 20:38)</a>:</h4>
<p>Ah yes, that's correct</p>



<a name="176504006"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176504006" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176504006">(Sep 24 2019 at 20:40)</a>:</h4>
<p>btw, that line will <em>always</em> clear <code>IsNotPromotable</code> for every type, but sometimes not <code>IsNotImplicitlyPromotable</code> due to the <code>Option&lt;bool&gt;</code> returned by <code>Qualif::in_any_value_of_ty</code></p>



<a name="176504157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176504157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176504157">(Sep 24 2019 at 20:42)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> is probably very interested in the <code>!Sync</code> question</p>



<a name="176504207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176504207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176504207">(Sep 24 2019 at 20:43)</a>:</h4>
<p>but I think the <code>Sync</code> thing is not something we can actually fix, I think it was cratered and bascially unfixable</p>



<a name="176504250"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176504250" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176504250">(Sep 24 2019 at 20:43)</a>:</h4>
<p>we could start linting it though</p>



<a name="176510338"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176510338" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176510338">(Sep 24 2019 at 21:54)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> my understanding is that the Sync stuff is a soundness hole?... so then we must fix it</p>



<a name="176510352"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176510352" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176510352">(Sep 24 2019 at 21:55)</a>:</h4>
<blockquote>
<p>I'm wrong</p>
</blockquote>
<p>What exactly were you wrong about?</p>



<a name="176510373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176510373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176510373">(Sep 24 2019 at 21:55)</a>:</h4>
<p><code>const FOO: Option&lt;Cell&lt;u32&gt;&gt; = None;</code> gets promoted</p>



<a name="176510385"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176510385" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176510385">(Sep 24 2019 at 21:55)</a>:</h4>
<p>so <code>&amp;FOO</code> is <code>&amp;'static Option&lt;Cell&lt;u32&gt;&gt;</code></p>



<a name="176510449"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176510449" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176510449">(Sep 24 2019 at 21:56)</a>:</h4>
<p>right; so we don't just look at the type</p>



<a name="176510501"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176510501" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176510501">(Sep 24 2019 at 21:56)</a>:</h4>
<p>well, we could start with a future incompat lint based on <a href="https://github.com/rust-lang/rust/pull/54424" target="_blank" title="https://github.com/rust-lang/rust/pull/54424">https://github.com/rust-lang/rust/pull/54424</a></p>



<a name="176510521"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176510521" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176510521">(Sep 24 2019 at 21:57)</a>:</h4>
<blockquote>
<p>right; so we don't just look at the type</p>
</blockquote>
<p>that's what I meant with "I'm wrong" :D</p>



<a name="176510527"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176510527" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176510527">(Sep 24 2019 at 21:57)</a>:</h4>
<p>and we're using zulip the wrong way</p>



<a name="176510535"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/176510535" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#176510535">(Sep 24 2019 at 21:57)</a>:</h4>
<p>having two conversations in one topic</p>



<a name="177710707"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/177710707" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#177710707">(Oct 09 2019 at 12:59)</a>:</h4>
<blockquote>
<p>so even <code>const FOO: Option&lt;Cell&lt;u32&gt;&gt; = None;</code> should not get promoted</p>
</blockquote>
<p>this is promotion looking into the initializer of a const, right? dang I almost forgot about that.<br>
we should re-fomulate this check as just looking at the final <em>value</em>, not the code computing it.</p>



<a name="177710744"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/177710744" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#177710744">(Oct 09 2019 at 12:59)</a>:</h4>
<p>oh lol <span class="user-mention" data-user-id="124288">@oli</span> already said that :)</p>



<a name="177710848"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/177710848" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#177710848">(Oct 09 2019 at 13:00)</a>:</h4>
<blockquote>
<p>but I think the <code>Sync</code> thing is not something we can actually fix, I think it was cratered and bascially unfixable</p>
</blockquote>
<p>yeah I want to come back to this eventually and see what we can do, but it's a sad mess</p>



<a name="177710880"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/177710880" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#177710880">(Oct 09 2019 at 13:01)</a>:</h4>
<blockquote>
<p><span class="user-mention silent" data-user-id="124288">oli</span> my understanding is that the Sync stuff is a soundness hole?... so then we must fix it</p>
</blockquote>
<p><span class="user-mention" data-user-id="126931">@centril</span>  well I think it is but our spec isn't detailed enough to give a definite answer ;)</p>



<a name="177710905"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/177710905" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#177710905">(Oct 09 2019 at 13:01)</a>:</h4>
<p>FTR, the issue for that is <a href="https://github.com/rust-lang/rust/issues/49206" target="_blank" title="https://github.com/rust-lang/rust/issues/49206">https://github.com/rust-lang/rust/issues/49206</a></p>



<a name="177711000"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/177711000" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#177711000">(Oct 09 2019 at 13:02)</a>:</h4>
<p>yeah that's fair</p>



<a name="177711015"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/177711015" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#177711015">(Oct 09 2019 at 13:02)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> back from vacation btw?</p>



<a name="177711036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/177711036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#177711036">(Oct 09 2019 at 13:02)</a>:</h4>
<p>I am, yes (the last 2 weeks was travelling for work, not vacation)</p>



<a name="177711045"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/177711045" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#177711045">(Oct 09 2019 at 13:02)</a>:</h4>
<p>just 606 emails to go in my Rust folder :P</p>



<a name="177711068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/177711068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#177711068">(Oct 09 2019 at 13:02)</a>:</h4>
<p>oh, and two POPL papers to revise, and a talk to prepare, and a thesis to write...</p>



<a name="177711087"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/177711087" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#177711087">(Oct 09 2019 at 13:03)</a>:</h4>
<p>Jesus mother of...</p>



<a name="177719070"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/177719070" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#177719070">(Oct 09 2019 at 14:30)</a>:</h4>
<p>so coming back to value-based promotion, my hope was that <a href="https://github.com/rust-rfcs/const-eval/pull/27" target="_blank" title="https://github.com/rust-rfcs/const-eval/pull/27">https://github.com/rust-rfcs/const-eval/pull/27</a> could help move in that direction by getting a better understanding of what it even is that we need</p>



<a name="177719091"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/177719091" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#177719091">(Oct 09 2019 at 14:30)</a>:</h4>
<p>and these days we have the value visitor which could be used to give more precise answers  to questions like "will dropping this value do anything"</p>



<a name="177719165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/177719165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#177719165">(Oct 09 2019 at 14:31)</a>:</h4>
<p><code>Option&lt;Cell&lt;u32&gt;&gt;</code> is particularly interesting though because I just recently changed Stacked Borrows to no longer be "value-based" here and instead treat this like a union... because otherwise things just become crazy complicated</p>



<a name="177719195"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/177719195" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#177719195">(Oct 09 2019 at 14:31)</a>:</h4>
<p>see <a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/204" target="_blank" title="https://github.com/rust-lang/unsafe-code-guidelines/issues/204">https://github.com/rust-lang/unsafe-code-guidelines/issues/204</a></p>



<a name="177719251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promoting%20consts%20with%20%60if%60/near/177719251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promoting.20consts.20with.20.60if.60.html#177719251">(Oct 09 2019 at 14:32)</a>:</h4>
<p><span class="user-mention" data-user-id="118594">@ecstatic-morse</span> ^</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>